<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>

		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/common.css" rel="stylesheet" />
		<link href="css/showloading.css" rel="stylesheet" />
		<title></title>
	</head>

	<body>
		<header id="header" class="mui-bar mui-bar-nav" style="background: #B01D29;text-align: center;">
			<img src="img/back.png" class=" tp-back mui-icon  mui-icon-left-nav mui-pull-left" style="height: 40px;width: 30px;"></img>
			<a class="mui-title " style="color: white;font: bold;font-size:20px ; ">商城</a>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view mui-grid-view mui-grid-9">
				<!--<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
					<a>
						<img src="img/mall.png" style="height: 40px;width: 40px;" />
						<div class="mui-media-body">小卖部</div>
					</a>
				</li>-->
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
					<a>
						<img src="img/buns.png" style="height: 40px;width: 40px;" />
						<div class="mui-media-body">订包子</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
					<a>
						<img src="img/yue.png" style="height: 40px;width: 40px;" />
						<div class="mui-media-body">查余额</div>

					</a>
				</li>

			</ul>
		</div>
	</body>
	<script src="js/mui.min.js"></script>
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/vue.min.js"></script>
	<script src="js/showloading.js"></script>
	<script src="js/common.js"></script>
	<script>
		mui.init();
		var userid = "";
		$(document).ready(function() {
			console.log("这是日志11");
			$('.mui-scroll-wrapper').scroll({});

			function goHistory() {
				var u = navigator.userAgent,
					app = navigator.appVersion;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
				var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				if(isAndroid) {
					console.log('android');
					window.app.back();
				} else if(isIOS) {
					console.log('ios');
					window.webkit.messageHandlers.GoBack.postMessage(null);
				}
			}
			$(".tp-back").on("click", function() {
				goHistory();
				localStorage.clear();
			});

			function getParams(url) {
				var theRequest = new Object();
				if(!url)
					url = window.location.href;
				console.log(url);
				if(url.indexOf("?") !== -1) {
					var str = url.substr(url.indexOf("?") + 1) + "&";
					var strs = str.split("&");
					for(var i = 0; i < strs.length - 1; i++) {
						var key = strs[i].substring(0, strs[i].indexOf("="));
						var val = strs[i].substring(strs[i].indexOf("=") + 1);
						theRequest[key] = val;
					}
				}
				return theRequest;
			}
			var params = getParams();
			//获取地址栏上的userName
			var userid = params.userId;
			userid = 4058;
			localStorage.setItem("userid", userid);
			console.log("userid:" + userid);
			getIdCard();
			var isallow = false;
			var userCard;

			function getIdCard() {
				if(userid != "") {
					mui.showLoading("正在加载..", "div");
					mui.ajax(oahost + 'oa/searchStaff', {
						data: {
							id: userid
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
							if(data.rows.length > 0) {
								if(data.rows[0].idCard != null) {

									isallow = true;
									userCard = JSON.stringify(data.rows[0].idCard).toString().replace(/\"/g, "");
									localStorage.setItem("usercard", userCard);
									console.log("sss：：" + userCard);
								} else {
									console.log("没有身份证信息");
									window.location.href = "IDCard.html";
								}
							}
							mui.hideLoading();

						},
						error: function(xhr, type, errorThrown) {
							//异常处理；
							console.log(type);
							mui.hideLoading();
						}
					});

				}
			}

//			mui.toast("userid:" + userid);
			$(".mui-table-view-cell").on("click", function() {
				var index = $(this).index();
				if(isallow) {
					switch(index) {
						case 0:
							window.location.href = "mall.html?childtype=1";
							break;
						case 1:
							window.location.href = "dish_record.html?childtype=1";
							//window.location.href = "http://10.71.23.49:8020/st/dish_record.html?userId=" + userid;
							break;
						case 2:
							//							window.location.href = "http://10.71.23.49:8020/st/dish_record.html?userId=" + userid;
							break;
					}
				} else {
					mui.toast("身份信息获取失败,请重试!")
				}
				console.log("索引" + index)
			})

		});
	</script>

</html>